package es.udc.fic.hamNeggs.dao;

import es.udc.fic.hamNeggs.manager.ProjectManager;
import es.udc.fic.hamNeggs.manager.UserManager;
import es.udc.fic.hamNeggs.pojo.Works;

import java.sql.Date;

public class InputWorks {
    private String user;

    private String project;

    private String dateStart;

    private String dateEnd;

    private String rol;

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getProject() {
        return project;
    }

    public void setProject(String project) {
        this.project = project;
    }

    public String getDateStart() {
        return dateStart;
    }

    public void setDateStart(String dateStart) {
        this.dateStart = dateStart;
    }

    public String getDateEnd() {
        return dateEnd;
    }

    public void setDateEnd(String dateEnd) {
        this.dateEnd = dateEnd;
    }

    public String getRol() {
        return rol;
    }

    public void setRol(String rol) {
        this.rol = rol;
    }

    public Works toWorks() {
        Works works = new Works();
        UserManager usrmng = new UserManager();
        ProjectManager prjmng = new ProjectManager();

        if (user != null && user != "")
            works.setUser(usrmng.getUser(new Long(user)));
        if (project != null && project != "")
            works.setProject(prjmng.getProject(new Long(project)));
        if (dateStart != null && dateStart != "")
            works.setDateStart(Date.valueOf(dateStart));
        if (dateEnd != null && dateEnd != "")
            works.setDateEnd(Date.valueOf(dateEnd));
        if (rol != null)
            works.setRol(Works.Rol.valueOf(rol));

        usrmng.close();
        prjmng.close();

        return works;
    }

    public void setWorks(Works wrk) {
        if (wrk.getUser() != null)
            user = wrk.getUser().getId().toString();
        if (wrk.getProject() != null)
            project = wrk.getProject().getId().toString();
        if (wrk.getDateStart() != null)
            dateStart = wrk.getDateStart().toString();
        if (wrk.getDateEnd() != null)
            dateEnd = wrk.getDateEnd().toString();
        if (wrk.getRol() != null)
            rol = wrk.getRol().getString();
    }
}
